// var lis=($("nav li a"));
// console.log(lis)
//     lis.mouseover(function(){
//     //   console.log($(this));
//     //   let thi=$(this)
//     // console.log(thi)
//     // thi.css({
//         // "color":"#fff"}).parent().siblings().children().css("color","#afafaf");
//  // $("nav .gd-ul").toggClass("gd-ul")

//     //   }  
// })

// lis.mouseout(()=>{
//     lis.css({
//         "color":"#afafaf"});

// })

if(document.cookie.split("=").length==2){
    var str= document.cookie.split("=")[1];
    str= str.replace(/^(\d{3})(\d{6})(\d{2})$/,(a,b,c,d)=>{
        return b+"******"+d
    })
    $("[href='logon.html']").html(str);
    $("[href='logon.html']").attr("href","#");
    $(".logout").css("display","inline");
    $("[href='parking.html']").css("display","none");  
} 

$("nav a").mouseover(() => {
    let e = event;
    let target = e.target || e.srcElement;
    $(target).children("ul:eq(0)").slideToggle();
    $(target).css({ "color": "#fff" });

})

$("nav a").mouseout(() => {
    let e = event;
    let target = e.target || e.srcElement;
    $(target).children("ul:eq(0)").slideToggle();
    $(target).css({ "color": "#afafaf" });
})


$.ajax({
    url: "http://172.168.20.103/HUAWEI/ALL/allphp.php",
    data: "hide=banner",
    dataType: "JSONP",
    success: (data) => {
       
        data.forEach((val, i) => {
            var li = $("<li></li>")
            var a = $(`<a target="_blank"></a>`)
            var img = $(`<img width="1920" height="482" style="background: url(${val.img}) ">`)
            a.append(img)
            li.append(a)
            $(".slides").append(li)
        })

        $(function ($, window, document, undefined) {

            Slider = function (container, options) {
                /*
                options = {
                    auto: true,
                    time: 3000,
                    event: 'hover' | 'click',
                    mode: 'slide | fade',
                    controller: $(),
                    activeControllerCls: 'className',
                    exchangeEnd: $.noop
                }
                */

                "use strict"; //stirct mode not support by IE9-

                if (!container) return;

                var options = options || {},
                    currentIndex = 0,
                    cls = options.activeControllerCls,
                    delay = options.delay,
                    isAuto = options.auto,
                    controller = options.controller,
                    event = options.event,
                    interval,
                    slidesWrapper = container.children().first(),
                    slides = slidesWrapper.children(),
                    length = slides.length,
                    childWidth = container.width(),
                    totalWidth = childWidth * slides.length;

                function init() {
                    var controlItem = controller.children();

                    mode();

                    event == 'hover' ? controlItem.mouseover(function () {
                        stop();
                        var index = $(this).index();

                        play(index, options.mode);
                    }).mouseout(function () {
                        isAuto && autoPlay();
                    }) : controlItem.click(function () {
                        stop();
                        var index = $(this).index();

                        play(index, options.mode);
                        isAuto && autoPlay();
                    });

                    isAuto && autoPlay();
                }

                //animate mode
                function mode() {
                    var wrapper = container.children().first();

                    options.mode == 'slide' ? wrapper.width(totalWidth) : wrapper.children().css({
                        'position': 'absolute',
                        'left': 0,
                        'top': 0
                    })
                        .first().siblings().hide();
                }

                //auto play
                function autoPlay() {
                    interval = setInterval(function () {
                        triggerPlay(currentIndex);
                    }, options.time);
                }

                //trigger play
                function triggerPlay(cIndex) {
                    var index;

                    (cIndex == length - 1) ? index = 0 : index = cIndex + 1;
                    play(index, options.mode);
                }

                //play
                function play(index, mode) {
                    slidesWrapper.stop(true, true);
                    slides.stop(true, true);

                    mode == 'slide' ? (function () {
                        if (index > currentIndex) {
                            slidesWrapper.animate({
                                left: '-=' + Math.abs(index - currentIndex) * childWidth + 'px'
                            }, delay);
                        } else if (index < currentIndex) {
                            slidesWrapper.animate({
                                left: '+=' + Math.abs(index - currentIndex) * childWidth + 'px'
                            }, delay);
                        } else {
                            return;
                        }
                    })() : (function () {
                        if (slidesWrapper.children(':visible').index() == index) return;
                        slidesWrapper.children().fadeOut(delay).eq(index).fadeIn(delay);
                    })();

                    try {
                        controller.children('.' + cls).removeClass(cls);
                        controller.children().eq(index).addClass(cls);
                    } catch (e) { }

                    currentIndex = index;

                    options.exchangeEnd && typeof options.exchangeEnd == 'function' && options.exchangeEnd.call(this, currentIndex);
                }

                //stop
                function stop() {
                    clearInterval(interval);
                }

                //prev frame
                function prev() {
                    stop();

                    currentIndex == 0 ? triggerPlay(length - 2) : triggerPlay(currentIndex - 2);

                    isAuto && autoPlay();
                }

                //next frame
                function next() {
                    stop();

                    currentIndex == length - 1 ? triggerPlay(-1) : triggerPlay(currentIndex);

                    isAuto && autoPlay();
                }

                //init
                init();

                //expose the Slider API
                return {
                    prev: function () {
                        prev();
                    },
                    next: function () {
                        next();
                    }
                }
            };

        }(jQuery, window, document));

        $(function () {
            var bannerSlider = new Slider($('#banner_tabs'), {
                time: 5000,
                delay: 400,
                event: 'hover',
                auto: true,
                mode: 'fade',
                controller: $('#bannerCtrl'),
                activeControllerCls: 'active'
            });
            $('#banner_tabs .flex-prev').click(function () {
                bannerSlider.prev()
            });
            $('#banner_tabs .flex-next').click(function () {
                bannerSlider.next()
            });
        })
    }
})


$.ajax({
    url: "http://172.168.20.103/HUAWEI/ALL/allphp.php",
    data: "hide=rxdanpin",
    dataType: "JSONP",
    success: (data) => {
        data.forEach(val => {
            if (val.id == 1) {
                var img = $(`<img src="${val.imgsrc}">`)
                $(".left:eq(2)").append(img)

            } else {

                for (var i in val) {

                    var li = $(`<li style="height: 290px;"></li>`)
                    var a = $(`<a></a>`)
                    var p = $(`<p></p>`)
                    var div = $(`<div > ${val.name}</div>`)
                    var h2 = $(`<h2 > ${val.miaoshu}</h2>`)
                    var h3 = $(`<h3 > ${val.money}</h3>`)
                    var img = $(`<img src="${val.imgsrc}">`)


                }
                p.append(img)
                a.append(p)
                a.append(div)
                a.append(h2)
                a.append(h3)
                li.append(a);
                $(".right:eq(1)>ul").append(li)
            }

        })

    }
})

$.ajax({
    url: "http://172.168.20.103/HUAWEI/ALL/allphp.php",
    data: "hide=jptuijian",
    dataType: "JSONP",//响应回来直接拖衣服
    success: (data) => {
        data.forEach(val => {
            if (val.id == 2) {
                for (var i in val) {
                    var li = $(`<li></li>`)
                    var a = $(`<a href='http://172.168.20.103/HUAWEI/ALL/huawei-mates.html?product=screen'></a>`)
                    var p = $(`<p></p>`)
                    var img = $(`<img src="${val.imgsrc}">`)
                    var div = $(`<div>${val.name}</div>`)
                    var h2 = $(`<h2>${val.miaoshu}</h2>`)
                    var h3 = $(`<h3>${val.money}</h3>`)
                }
            } else {
                for (var i in val) {
                    var li = $(`<li></li>`)
                    var a = $(`<a></a>`)
                    var p = $(`<p></p>`)
                    var img = $(`<img src="${val.imgsrc}">`)
                    var div = $(`<div>${val.name}</div>`)
                    var h2 = $(`<h2>${val.miaoshu}</h2>`)
                    var h3 = $(`<h3>${val.money}</h3>`)

                }
            }

            p.append(img)
            a.append(p)
            a.append(div)
            a.append(h2)
            a.append(h3)
            li.append(a)
            $(".container:eq(2) ul").append(li)
        })
    }
})






























  // $("header input")


  /**
 * slider插件可悬停控制
 */;





$(function () {
    var $top = $('.sec-mainNav').offset().top + $('.sec-mainNav').height()
    //左侧导航动画
    $('.sec-mainNav li').on('mouseenter', function () {
        var $height = $(this).offset().top + $(this).find('.menu-panel').outerHeight()
        $(this).find('.menu-panel').show()
        if ($height - $top >= 0) {
            $(this).find('.menu-panel').css({
                top: -($height - $top) + 'px'
            })
        }

    })
    $('.sec-mainNav li').on('mouseleave', function () {
        $(this).find('.menu-panel').hide()
    })
})
